package com.ymdx.util;

import com.ymdx.entity.IdEntity;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * Created by yangliwei on 2017/8/14.
 */
public class Page<E extends IdEntity> implements Serializable {
    private static final long serialVersionUID = 3486190032577428250L;
    private Integer pageNo = 1;//这里默认为1 为了和前端数据不起冲突，后台出数据setFirstResult 从0开始的
    private Integer pageSize = 9;
    /**
     * 数据总条数
     **/
    protected long totalCount = 0;
    /**
     * 是否启用自动统计,默认开启
     **/
    protected boolean autoCount = true;

    /**
     * 结果集
     **/
    protected List<E> result = Collections.emptyList();

    public void setResult(final List<E> result) {
        this.result = result;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        if(pageNo == null || pageNo<1){
            pageNo= 1;
        }
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if(pageSize == null || pageSize<1){
            pageSize = 9;
        }
        this.pageSize = pageSize;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public boolean isAutoCount() {
        return autoCount;
    }

    public void setAutoCount(boolean autoCount) {
        this.autoCount = autoCount;
    }

    public List<E> getResult() {
        return result;
    }
}
